package org.example.controller;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.service.DemoService;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/demo")
@AllArgsConstructor
public class DemoController {

    private final DemoService service;

    @GetMapping("{name}")
    public String hello(@PathVariable("name") String name) {
//        String s = TraceContext.traceId();
//        System.out.println("traceId: "+s);
//        System.out.println("segmentId:"+TraceContext.segmentId());
//        System.out.println("spanId:"+TraceContext.spanId());
//        log.info("welcome, {}", name);
        new Thread(() -> log.info("异步打印")).start();
        return "welcome, " + service.hello(name);
    }

    @RequestMapping("hi")
    public String hi(int sleep) throws InterruptedException {
        Thread.sleep(sleep);
        return "hi";
    }
}
